import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.util.List;

/**
 * @author ml
 * @create 2017-07-28--14:59
 */
public class test {

    public static void main(String[] args) throws Exception {
        select();
    }
    //查询所有name的值
    private static void select() throws Exception {
        SAXReader saxReader=new SAXReader();
        Document document=saxReader.read("demo\\src\\1.xml");
        List<Node> list=document.selectNodes("//name");
        for(int i=0;i<list.size();i++)
            System.out.println(list.get(i).getText());
    }
    //查询id=stu1的学生的name的值
    private static void select2() throws Exception {
        SAXReader saxReader=new SAXReader();
        Document document=saxReader.read("src/1.xml");
        Node node=document.selectSingleNode("//student[@id='stu1']/name");
        System.out.println(node.getText());
    }
}
